#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <queue>
#include <stack>

using namespace std;


void Test1()
{
	string s("helloworld");
	cout << s.length() << " " << s.size() << endl;
	queue<char, string> q(s);
}

bool is_left_brackets(char ch)
{
    return ch == '(';
}
bool is_right_brackets(char ch)
{
    return ch == ')';
}
bool chkParenthesis(string A, int n) {
    // write code here
    if (A.size() % 2 != 0)
    {
        return false;
    }
    queue<char> q;
    stack<char> s;
    for (auto e : A)
    {
        q.push(e);
    }
    while (!q.empty())
    {
        if (is_left_brackets(q.front()))
        {
            s.push(q.front());
            q.pop();
        }
        else if (is_right_brackets(q.front()))
        {
            if (s.empty())
            {
                return false;
            }
            if (is_left_brackets(s.top()))
            {
                s.pop();
                q.pop();
            }
        }
        else
        {
            return false;
        }
    }
}

int main()
{
	//Test1();
    string s("((()))");
    chkParenthesis(s, 6);
	return 0;
}